package com.epalmpay.controller.channel.lottery;

import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.epalmpay.commom.BaseController;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.system.BaseOutDTO;
import com.epalmpay.dto.system.PageDTO;
import com.epalmpay.entity.ActivityLottery;
import com.epalmpay.entity.ActivityLotteryAward;
import com.epalmpay.dto.activity.ActivityLotteryAwardInDTO;
import com.epalmpay.dto.activity.ActivityLotteryInDTO;
import com.epalmpay.dto.activity.ActivityLotteryListOutDTO;
import com.epalmpay.dto.activity.ActivityLotteryRecordInDTO;
import com.epalmpay.service.activity.ILotteryService;



@Controller
@RequestMapping(value="/channel/lottery")
public class LotteryController extends BaseController{

	
	@Resource
	ILotteryService lotteryService;
	
	
	/**
	 * 抽奖活动列表
	 * @param activityLotteryInDTO
	 * @param pageDTO
	 * @return
	 */
	@RequestMapping(value="/lotteryList")
	@ResponseBody
	public BaseOutDTO  agentList(ActivityLotteryInDTO activityLotteryInDTO,PageDTO pageDTO){
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		try {		
			ActivityLotteryListOutDTO lotteryListOutDTO = lotteryService.lotteryList(activityLotteryInDTO,pageDTO);
			
			if(lotteryListOutDTO!=null){
				lotteryListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
				return lotteryListOutDTO;
			}else{
				baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理结果为空");
			}	
		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return baseOutDTO;
	}
	
	/**
	 * 根据id查询抽奖活动详情
	 * @param lotteryInDTO
	 * @return
	 */
	@RequestMapping(value="/findLotteryId")
	@ResponseBody
	public ActivityLottery  findLotteryId(ActivityLotteryInDTO lotteryInDTO){
		ActivityLottery al = new ActivityLottery();
		try {		
			ActivityLottery activityLottery = lotteryService.selectActivityLotteryId(lotteryInDTO.getId());
			if(activityLottery!=null){
				activityLottery.setErrorCode(Rescode.SUCCESS, "处理成功");
				return activityLottery;
			}else{
				al.setErrorCode(Rescode.DEFAULT_PREFIX, "处理结果为空");
			}	
		} catch (ApplicationException ae) {
			al.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		}
		catch (Exception e) {
			al.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return al;
	}
	
	
	
	/**
	 * 根据id查询抽奖活动详情
	 * @param lotteryInDTO
	 * @return
	 */
	@RequestMapping(value="/findactivityLotteryAwardId")
	@ResponseBody
	public ActivityLotteryAward  findactivityLotteryAwardId(ActivityLotteryAward at){
		ActivityLotteryAward al = new ActivityLotteryAward();
		try {		
			ActivityLotteryAward activityLotteryAward = lotteryService.activityLotteryAwardId(at.getId());
			if(activityLotteryAward!=null){
				activityLotteryAward.setErrorCode(Rescode.SUCCESS, "处理成功");
				return activityLotteryAward;
			}else{
				al.setErrorCode(Rescode.DEFAULT_PREFIX, "处理结果为空");
			}	
		} catch (ApplicationException ae) {
			al.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		}
		catch (Exception e) {
			al.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return al;
	}
	
	
	
	/**
	 * 保存抽奖活动
	 * @param activityLotteryInDTO
	 * @return
	 */
	@RequestMapping(value="/saveLottery")
	@ResponseBody
	public BaseOutDTO  saveLottery(ActivityLotteryInDTO activityLotteryInDTO){
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		try {		
			return lotteryService.saveActivityLottery(activityLotteryInDTO);	
		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.errMsg);
			ae.printStackTrace();
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		 return baseOutDTO;
	}

	
	/**
	 * 更改抽奖活动
	 * @param activityLotteryInDTO
	 * @return
	 */
	@RequestMapping(value="/updateLottery")
	@ResponseBody
	public BaseOutDTO  updateLottery(ActivityLotteryInDTO activityLotteryInDTO){
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		try {		
			return lotteryService.updateActivityLottery(activityLotteryInDTO);	
		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.errMsg);
			ae.printStackTrace();
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		 return baseOutDTO;
	}
	
	
	
	/**
	 * 奖品等级列表
	 * @param activityLotteryInDTO
	 * @return
	 */
	@RequestMapping(value="/lotteryAwardList")
	@ResponseBody
	public ActivityLotteryListOutDTO  lotteryAwardList(ActivityLotteryAwardInDTO activityLotteryAwardInDTO){
		ActivityLotteryListOutDTO baseOutDTO = new ActivityLotteryListOutDTO();
		try {		
			ActivityLotteryListOutDTO lotteryListOutDTO = lotteryService.activityLotteryAwardList(activityLotteryAwardInDTO);
			if(lotteryListOutDTO!=null){
				lotteryListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
				return lotteryListOutDTO;
			}else{
				baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理结果为空");
			}	
		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return baseOutDTO;
	}
	
	
	
	/**
	 * 保存奖品等级表
	 * @param activityLotteryInDTO
	 * @return
	 */
	@RequestMapping(value="/saveLotteryAward")
	@ResponseBody
	public BaseOutDTO  saveLotteryAward(ActivityLotteryAwardInDTO activityLotteryAwardInDTO){
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		try {		
			return lotteryService.saveActivityLotteryAward(activityLotteryAwardInDTO);	
		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.errMsg);
			ae.printStackTrace();
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		 return baseOutDTO;
	}

	
	/**
	 * 更改奖品等级
	 * @param 
	 * @return
	 */
	@RequestMapping(value="/updateLotteryAward")
	@ResponseBody
	public BaseOutDTO  updateLotteryAward(ActivityLotteryAwardInDTO activityLotteryAwardInDTO){
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		try {		
			return lotteryService.updateActivityLotteryAward(activityLotteryAwardInDTO);	
		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.errMsg);
			ae.printStackTrace();
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		 return baseOutDTO;
	}
	
	
	
	/**
	 * 获奖者列表
	 * @param activityLotteryInDTO
	 * @param pageDTO
	 * @return
	 */
	@RequestMapping(value="/activityLotteryRecordList")
	@ResponseBody
	public BaseOutDTO  activityLotteryRecordList(ActivityLotteryRecordInDTO activityLotteryRecordInDTO,PageDTO pageDTO){
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		try {		
			ActivityLotteryListOutDTO lotteryListOutDTO = lotteryService.activityLotteryRecordList(activityLotteryRecordInDTO,pageDTO);
			
			if(lotteryListOutDTO!=null){
				lotteryListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
				return lotteryListOutDTO;
			}else{
				baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理结果为空");
			}	
		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return baseOutDTO;
	}
	

	@RequestMapping(value="/verifyAwards")
	@ResponseBody
	public BaseOutDTO  verifyAwards(ActivityLotteryRecordInDTO activityLotteryRecordInDTO){
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		try {		
			return lotteryService.updateVerifyAwards(activityLotteryRecordInDTO.getId());	
		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, ae.errMsg);
			ae.printStackTrace();
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		 return baseOutDTO;
	}
	
	
	
	
	
	
}



